package controller

import (

	"github.com/gofiber/fiber/v2"
	"gowork/microSignalSMSSending/service"
	"strconv"
)

type AdviserController struct {
	AdviserServiceImf *service.AdviserServiceImf
}

func (ac *AdviserController) GetWhetherToPopUp(c *fiber.Ctx) error {

	ac.AdviserServiceImf = new(service.AdviserServiceImf)

	account := c.FormValue("account")
	customerIdStr := c.FormValue("customerId")
	customerId, err := strconv.ParseInt(customerIdStr,10, 64)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return err
	}

	res, err := ac.AdviserServiceImf.GetWhetherToPopUp(account, customerId)
	if err != nil {
		c.JSON(fiber.Map{
			"code":    500,
			"data":    nil,
			"message": err.Error(),
		})
		return nil
	}

	c.JSON(fiber.Map{
		"code":    200,
		"data":    res["popUpOrNot"],
		"message": "成功",
	})
	return nil
}